package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /*
     * @Description  分页条件查询并按下单时间排序
     * @Param [ordersPageQueryDTO]
     * @return com.github.pagehelper.Page<com.sky.entity.Orders>
     **/
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /*
     * @Description  根据id查询订单详情
     * @Param [id]
     * @return com.sky.entity.Orders
     **/
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * @Description  统计订单数量
     * @Param [status]
     * @return java.lang.Integer
     **/
    @Select("select count(id) from orders where status=#{status}")
    Integer countStatus(Integer status);

    /*
     * @Description  根据订单状态和订单时间查询订单
     * @Param [status, orderTime]
     * @return java.util.List<com.sky.entity.Orders>
     **/
    @Select("select * from orders where status=#{status} and order_time < #{orderTime}")
    List<Orders> getBYStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    /*
     * @Description  查询每天的营业额
     * @Param [map]
     * @return java.lang.Double
     **/
    Double sumByMap(Map map);

    /*
     * @Description  查询订单数量
     * @Param [map]
     * @return java.lang.Integer
     **/
    Integer countByMap(Map map);

    /*
     * @Description  查询销量前10的菜品
     * @Param [begin, end]
     * @return com.sky.dto.GoodsSalesDTO
     **/
    List<GoodsSalesDTO> getSalesTop(LocalDateTime begin, LocalDateTime end);
}
